package Z06XianCheng.XC03TongBu;

// 给方法加锁

public class hero11 {

    public String name;
    public float hp;

    public int damage;

    public void AttackHero(Z06XianCheng.XC01StartXianCheng.Hero h){

        try {
            Thread.sleep(1000);
        }catch (InterruptedException e ){
            e.printStackTrace();
        }

        h.hp -= damage;
        System.out.printf("%s 正在攻击 %s, %s的血变成了 %.0f%n",name,h.name,h.name,h.hp);

        if (h.isDead()){
            System.out.println(h.name + "没了！");
        }
    }

    public boolean isDead() {
        return 0 >= hp ? true:false;
    }

    public  synchronized void recover(){
        hp += 1;
    }

    public void hurt(){
        synchronized(this){ hp -= 1;}
    }

}
